<template>
	<view class="work-container">

		<!-- 宫格组件 -->
		<view class="grid-body">
			<uni-grid :column="4" :showBorder="false" @change="changeGrid">
				<uni-grid-item :index="index" v-for="(item,index) in menuData" :key="index">
					<view class="grid-item-box">
						<uni-icons class="home-icon" :type="iconData[index].type"
							:style="{backgroundColor: iconData[index].color}" color="white" size="30"></uni-icons>
						<text class="text">{{item.name}}</text>
					</view>
				</uni-grid-item>
			</uni-grid>
		</view>
	</view>
</template>

<script>
	import {
		getStockGroup
	} from "@/api/eye/myAttention.js"
	export default {
		data() {
			return {
				menuData: [],
				iconData: []
			}
		},
		onLoad() {
			this.getStockGroup();
		},
		methods: {
			getStockGroup() {
				getStockGroup().then( res => {
					this.menuData = res.data
					console.log( this.menuData )
					this.iconData = new Array( this.menuData.length )
					let type = [ 'fire-filled', 'wallet', 'vip-filled', 'medal-filled', 'starhalf', 'pyq' ]
					let color = [ '#FF4500', '#FF8C00', '#FFD700', '#00CED1', '#1E90FF', '#00BABD' ]
					for ( let i = 0; i < this.iconData.length; i++ ) {
						this.iconData[ i ] = new Object()
						this.iconData[ i ].type = type[ i % 5 ]
						this.iconData[ i ].color = color[ i % 5 ]
					}
				} )
			},
			changeGrid( e ) {
				uni.navigateTo( {
					url: '/pages/stock/attentionDetail/index' + '?id=' + this.menuData[ e.detail.index ].id
				} )
			}
		}
	}
</script>

<style lang="scss">
	@import "@/static/font/ali/iconfont.css";

	/* #ifndef APP-NVUE */
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #fff;
		min-height: 100%;
		height: auto;
	}

	view {
		font-size: 14px;
		line-height: inherit;
	}

	/* #endif */
	.text {
		text-align: center;
		font-size: 26rpx;
		margin-top: 10rpx;
	}

	.grid-item-box {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 15px 0;
	}
</style>